package com.ice.delay.task.controller;

import com.ice.delay.task.core.model.DelayTaskModule;
import com.ice.delay.task.service.DelayTaskModuleService;
import com.ice.delay.task.vo.req.DelayTaskModuleEnabledVoReq;
import com.ice.delay.task.vo.req.DelayTaskModuleQueryReq;
import com.ice.delay.task.vo.req.DelayTaskModuleUpdateVoReq;
import com.ice.delay.task.vo.req.DelayTaskModuleVoReq;
import com.ice.delay.task.vo.res.DelayTaskModuleVoRes;
import com.ice.framework.common.annotation.AutoResult;
import com.ice.framework.common.base.RPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wangwei
 * @Date 2022/4/21 21:24
 */
@RequestMapping("/module")
@Controller
public class DelayTaskModuleController {

    @Autowired
    private DelayTaskModuleService delayTaskModuleService;

    /**
     * 保存延时任务模块
     * @Author wangwei
     * @Date 2022/4/28
     */
    @AutoResult
    @ResponseBody
    @PostMapping("saveDelayTaskModule")
    public void saveDelayTaskModule(@RequestBody @Valid DelayTaskModule delayTaskModule) {
        delayTaskModuleService.saveDelayTaskModule(delayTaskModule);
    }

    @AutoResult
    @ResponseBody
    @GetMapping("listDelayTaskModule")
    public List<DelayTaskModule> listDelayTaskModule(){
        return delayTaskModuleService.listDelayTaskModule();
    }

    @AutoResult
    @ResponseBody
    @PostMapping("page")
    public RPage<DelayTaskModuleVoRes> page(@RequestBody RPage<DelayTaskModuleVoReq> page) {
        return delayTaskModuleService.pageModule(page);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("findModule")
    public DelayTaskModuleVoRes findModule(@RequestBody @Valid DelayTaskModuleQueryReq module) {
        return delayTaskModuleService.findModule(module);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("updateModule")
    public void updateModule(@RequestBody @Valid DelayTaskModuleUpdateVoReq updateModule){
        delayTaskModuleService.updateModule(updateModule);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("/enabled")
    public void enabled(@RequestBody @Valid DelayTaskModuleEnabledVoReq delayTaskModuleEnabledVoReq) {
        delayTaskModuleService.enabled(delayTaskModuleEnabledVoReq);
    }

    @RequestMapping("/index")
    public String index(){
        return "/admin/task_delay_module";
    }
}
